// =================================================================
// File: read.cpp
// Desc: Contains function for reading from a file
// =================================================================

// =================================================================
// INCLUDES
// =================================================================

#include <string>
#include "FSManager.h"
#include "File.h"
#include "commands.h"
#include "config.h"

using namespace std;

// =================================================================
// FUNCTIONS
// =================================================================

// =================================================================
// Name: read
// Desc: Sets specified directory as the current directory
// Args: int fd - the file descriptor to read from
//	 int bytesToRead - the amount of bytes to be read
//       FSManager* fsm - pointer to active FSManager object
// Rets: the data that was read.
// =================================================================
string read(int fd, int bytesToRead, FSManager *fsm){

    File *file = fsm->GetOpenFile(fd);

    if(file == NULL)
        return NULL;
    
    if(file->GetMode() == READ_MODE || file->GetMode() == READWRITE_MODE){
    string data = fsm->ReadFile(file,bytesToRead);
    return data;
    }
    else{
        return NULL;
    }
}
